Skip to content

Add language-wide chat routing via TOC and scope selector in chat form#222

Merged
na-trium-144 merged 8 commits into
mainfrom
copilot/implement-chat-functionality
Jul 21, 2026
Merged

Add language-wide chat routing via TOC and scope selector in chat form#222
na-trium-144 merged 8 commits into
mainfrom
copilot/implement-chat-functionality

Conversation

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Current chat answers only reference the currently open page. This change adds a user-selectable scope so questions can be answered from either the current page or the entire current language, with AI routing to the most relevant page using that language’s TOC.

  • Scope selection in chat UI

    • Added radio options to the chat form:
      • このページの内容について質問
      • (言語名)全体について質問
    • Sends questionScope: "page" | "language" with chat requests.
  • Language-wide routing flow in /api/chat

    • For questionScope === "language":
      • Builds a routing prompt from the current language’s page list + section titles.
      • Asks AI to return the most relevant page slug (or null).
      • Loads routed page sections and uses them as chat context.
    • For questionScope === "page":
      • Preserves existing behavior (current page sections).
  • Chat event payload and cache revalidation alignment

    • Extended initial stream event with pagePath of the actual routed target.
    • Client now revalidates chat against the routed page path, not always the current page.
    • Keeps section scroll behavior only when routed page matches current page.
// request payload
body: JSON.stringify({
  path,
  userQuestion,
  questionScope, // "page" | "language"
  sectionContent,
  replOutputs,
  files,
  execResults,
})

// streamed chat-start event
{ type: "chat", chatId, sectionId, pagePath }

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 21, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
my-code d9f60ea Commit Preview URL

Branch Preview URL
Jul 21 2026, 05:20 PM

Copilot AI changed the title [WIP] Implement feature to categorize questions by page Add language-wide chat routing via TOC and scope selector in chat form Jul 21, 2026
Copilot AI requested a review from na-trium-144 July 21, 2026 02:33
Copilot AI review requested due to automatic review settings July 21, 2026 16:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the docs chat feature to support a user-selectable question scope (“current page” vs “entire language”) and adds an AI-driven routing step that selects the most relevant page (based on the language TOC) when the language scope is chosen.

Changes:

  • Added questionScope: "page" | "language" to chat requests and updated /api/chat to optionally route to another page within the same language.
  • Extended the initial streamed chat event with pagePath so the client can revalidate and scroll against the routed page.
  • Updated the chat form UI to include a scope selector and to adjust revalidation/scroll behavior based on the routed page.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
app/api/chat/route.ts Adds language-wide routing flow and streams back the routed pagePath, using routed sections as chat context.
app/(docs)/@docs/[lang]/[pageId]/pageContent.tsx Passes langName into ChatForm for rendering the language-scope radio label.
app/(docs)/@docs/[lang]/[pageId]/chatForm.tsx Adds scope selector UI, sends questionScope, and revalidates/scrolls based on routed pagePath.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/api/chat/route.ts
Comment on lines +82 to +91
for (const page of langEntry.pages) {
const sections = await getMarkdownSections(path.lang, page.slug);
const sectionTitles = sections
.map((s) => s.title.trim())
.filter((title) => title.length > 0)
.join(" / ");
routePrompt.push(
`- slug: ${page.slug} | 章題: ${page.title} | セクション: ${sectionTitles}`
);
}
Comment thread app/api/chat/route.ts Outdated
Comment on lines 25 to 29
interface ChatFormProps {
path: PagePath;
langName: string;
sectionContent: DynamicMarkdownSection[];
close: () => void;
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@na-trium-144
na-trium-144 marked this pull request as ready for review July 21, 2026 17:18
@na-trium-144
na-trium-144 merged commit c0a9e14 into main Jul 21, 2026
9 checks passed
@na-trium-144
na-trium-144 deleted the copilot/implement-chat-functionality branch July 21, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

どのページで質問したらいいか分からない場合など、チャットを適切なページに振り分ける機能

3 participants